package web.blogsphere.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import web.blogsphere.mapper.BlogMapper;
import web.blogsphere.mapper.UserInfoMapper;
import web.blogsphere.model.BlogInfo;
import web.blogsphere.model.UserInfo;

/**
 * @ClassName UserService
 * @Description TODO
 * @Author ZJX
 * @Date 2024/9/4 14:52
 * @Version 1.0
 */
@Service
@Slf4j
public class UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private BlogMapper blogMapper;

    public UserInfo selectByName(String userName) {
        return userInfoMapper.selectByName(userName);
    }

    public UserInfo selectById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    public UserInfo getAuthorInfo(Integer blogId) {
        BlogInfo blogInfo = blogMapper.selectById(blogId);
        if (blogInfo == null && blogInfo.getUserId() <= 0){
            log.error("图书不存在或者作者信息不合法");
            return null;
        }
        UserInfo userInfo = userInfoMapper.selectById(blogInfo.getUserId());
        return userInfo;
    }
}
